package com.ffapp.demo.bean;


import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.amap.api.maps.model.LatLng;
import com.ffapp.demo.R;
import com.ffapp.demo.greendao.GreenDaoUtils;
import com.ffapp.demo.map.GPSUtil;

public class MapDataListData  {

//    public static final int TYPE_BUILDING_

    private String title;
    private String des;
    private String id;
    private double longitude;
    private double latitude;
    private String type;
    private String type_name;
    private int resIcon;
    private String auditStatus;
    private String linkId;
    private String profile;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getResIcon() {
        return resIcon;
    }

    public void setResIcon(int resIcon) {
        this.resIcon = resIcon;
    }

    @JSONField(serialize = false)
    public LatLng getLatlng() {
        double[] gprs = GPSUtil.gps84_To_Gcj02(latitude,longitude);
        LatLng latLng = new LatLng(gprs[0], gprs[1]);
        return latLng;
    }

    @JSONField(serialize = false)
    public static MapDataListData getFromWarnMapData(WarnMapData warnMapData){
        MapDataListData listData = new MapDataListData();
        listData.setId(warnMapData.getId());
        listData.setLinkId(warnMapData.getLinkId());
        listData.setTitle(warnMapData.getName());
        listData.setLatitude(Double.valueOf(TextUtils.isEmpty(warnMapData.getLatitude())?"0":warnMapData.getLatitude()));
        listData.setLongitude(Double.valueOf(TextUtils.isEmpty(warnMapData.getLatitude())?"0":warnMapData.getLongitude()));
        listData.setType(warnMapData.getMap_type());
        listData.setAuditStatus(warnMapData.getAuditStatus());


//        listData.setDes(warnMapData.getAddress());
        switch (warnMapData.getMap_type()){
            case GreenDaoUtils.TYPE_BUILDING:
                listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_icon_jzdw_r:R.drawable.map_icon_icon_jzdw_o);
                listData.setType_name("建筑");
                break;
            case GreenDaoUtils.TYPE_RISK:
                listData.setType_name("单位隐患");
                listData.setTitle(warnMapData.getUnitName());
                listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_icon_dwyh_r:R.drawable.map_icon_icon_dwyh_o);
                break;
            case GreenDaoUtils.TYPE_STATION:
                listData.setType_name("微型消防站");
//                listData.setResIcon(R.drawable.map_icon_wxxfz);
                listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_icon_wxxfz_r:R.drawable.map_icon_icon_wxxfz_o);
                break;
            case GreenDaoUtils.TYPE_TRAIN:
                listData.setType_name("单位演练");
//                listData.setTitle(warnMapData.getUnitName());
                listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_icon_drill_r:R.drawable.map_icon_icon_drill_o);
                break;
            case GreenDaoUtils.TYPE_UNIT:
                listData.setType_name("单位");
                listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_map_unit_r:R.drawable.map_icon_map_unit_o);
                break;
            case GreenDaoUtils.TYPE_WATER:
                listData.setProfile(warnMapData.getProfile());
                if(TextUtils.isEmpty(warnMapData.getType())){
//                    listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_water2_published:R.drawable.map_icon_water2_pending);
                }else if(warnMapData.getType().equals(WarnMapData.WATER_TYPE_HYDRANT)){
                    listData.setType_name("消火栓");
                    if(warnMapData.getStatus().equals(WarnMapData.SATUS_USE)){
                        listData.setDes("可用");
                        listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_map_xfs_r:R.drawable.map_icon_map_xfs_o);
                    }else {
                        listData.setDes("不可用");
                        //不可用消火栓
                        listData.setResIcon(R.drawable.map_icon_map_xfs_g);
                    }
                }else if(warnMapData.getType().equals(WarnMapData.WATER_TYPE_POOL)){
                    listData.setType_name("消防水池");
                    listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_icon_pool_r:R.drawable.map_icon_icon_pool_o);
                }else if(warnMapData.getType().equals(WarnMapData.WATER_TYPE_WATER)){
                    listData.setType_name("天然水源");
                    listData.setResIcon(warnMapData.getAuditStatus_BOOLEAN()? R.drawable.map_icon_icon_water_r:R.drawable.map_icon_icon_water_o);
                }
                break;
        }
        return listData;
    }

    public void toDetail(Activity activity,boolean isCanEdit){
        if(TextUtils.isEmpty(type)){
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putString("id",id);
        bundle.putBoolean("is_edit",false);
        if(isCanEdit){
            bundle.putBoolean("is_can_edit",isCanRecollect());
//            bundle.putBoolean("is_can_delete",true);
        }else {
            bundle.putBoolean("is_can_edit",false);
//            bundle.putBoolean("is_can_delete",false);
        }
    }

    public String getLinkId() {
        return linkId;
    }

    public void setLinkId(String linkId) {
        this.linkId = linkId;
    }

    public String getAuditStatus() {
        return auditStatus;
    }

    @JSONField(serialize = false)
    public boolean isCanRecollect() {
        if(type.equals(GreenDaoUtils.TYPE_TRAIN))return false;
        if(type.equals(GreenDaoUtils.TYPE_RISK))return false;
        switch (auditStatus) {
            case "0":
                return false;//"待审核";
            case "1":
                return true;//"已审核";
            case "2":
                return true;//"审核不通过";
        }
        return true;
    }
    public void setAuditStatus(String auditStatus) {
        this.auditStatus = auditStatus;
    }

    public String getType_name() {
        return type_name;
    }

    public void setType_name(String type_name) {
        this.type_name = type_name;
    }

    public String getProfile() {
        return profile;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }

    @JSONField(serialize = false)
    public static MapDataListData getFromCarLocationData(DispatchListData data){
        MapDataListData listData = new MapDataListData();
        listData.setId(data.getId());
        StringBuilder builder = new StringBuilder();
        builder.append(data.getPlateNo()+"  "+data.getName());
        if(!TextUtils.isEmpty(data.getSpeed())){
            builder.append(" "+data.getSpeed()+"km/h");
        }
        listData.setTitle(builder.toString());
//        listData.setDes(data.getDeptName());
        listData.setDes(data.getAbbreviation());
        listData.setLatitude(data.getLatitude());
        listData.setLongitude(data.getLongitude());
        listData.setResIcon(R.drawable.car_map_icon);
        return  listData;
    }
}
